package com.zzuli.yxy.task.springDataPipeline;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zzuli.yxy.entity.Singer;
import com.zzuli.yxy.mapper.SingerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * 会获取一种数据
 * singer：歌手id 歌手图片 歌手简介
 * @auther pony
 * @create 2023-04-05 14:12
 */
@Component
public class SingerImgPipeline implements Pipeline {
    @Autowired
    private SingerMapper singerMapper;
    @Override
    public void process(ResultItems resultItems, Task task) {
        //1、获取 singer，存入数据库
        Singer singerTask = resultItems.get("singer");

        // 保存数据到数据库
        LambdaUpdateWrapper<Singer> uw = new LambdaUpdateWrapper<>();
        uw.eq(Singer::getSingerId, singerTask.getSingerId());
        uw.set(Singer::getSingerImg, singerTask.getSingerImg());
        uw.set(Singer::getSingerRemarks, singerTask.getSingerRemarks());
        singerMapper.update(singerTask,uw);
    }
}
